package com.dt76.smallloanbackenduser.controller.afterloan;


import com.dt76.smallloanbackenduser.pojo.afterloan.RepaymentCommitInfo;
import com.dt76.smallloanbackenduser.pojo.afterloan.RepaymentInfo;
import com.dt76.smallloanbackenduser.pojo.afterloan.RepaymentQualification;
import com.dt76.smallloanbackenduser.remote.afterloan.RepaymentRemote;
import com.dt76.smallloanbackenduser.utils.PageResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
public class RepaymentController {

    private final RepaymentRemote repaymentRemote;

    public RepaymentController(RepaymentRemote repaymentRemote) {
        this.repaymentRemote = repaymentRemote;
    }

    @GetMapping("/repaymentManager")
    public String jumpToRepayment() {
        return "/pages/afterloan/repaymentManager";
    }

    @ResponseBody
    @PostMapping("/repayment/list/{page}/{size}")
    public PageResult getPageList(@RequestBody RepaymentQualification q, @PathVariable Integer page, @PathVariable Integer size) {
        return repaymentRemote.getPageList(q, page, size);
    }

    @ResponseBody
    @GetMapping("/repayment/id/{id}")
    public List<RepaymentInfo> getById(@PathVariable Integer id) {
        return repaymentRemote.getById(id);
    }

    @ResponseBody
    @PostMapping("/repayment/commitNormal/{repaymentId}/{loanId}")
    public Map<String, Object> commitRepaymentConfirm(@RequestBody RepaymentCommitInfo q, @PathVariable Integer repaymentId, @PathVariable Integer loanId) {
        return repaymentRemote.commitRepaymentConfirm(q, repaymentId, loanId);
    }

}
